package ooo.reindeer.cedf.components.flow;

import ooo.reindeer.cedf.Cedf;
import ooo.reindeer.commons.Property;
import ooo.reindeer.logging.ILogger;
import ooo.reindeer.logging.LogUtil;

public class Step {

    private static final ILogger logger = LogUtil.getLogger(Step.class);

    private String id;
    private IJob job;

    public boolean init(String id, Property config) {
        logger.info("init:jobId=[{}] config=[{}]",id,config);
        this.id = id;
        String job_class = config.value("");
        if (job_class.isEmpty()) return false;
        job = Cedf.loadComponent(id,job_class, config);
//        logger.debug("init:jobId=[{}] jobObject=[{}]",id,job);
        return job != null;
    }

    public String getId() {
        return id;
    }

    public String exec(Object data) {

        String ret= job.exec(data);
        ret=(ret==null)?"":ret;
        return ret;
    }

    @Override
    public String toString() {
        return "Step{" +
                "id='" + id + '\'' +
                ", jobCLass=" + job.getClass() +
                '}';
    }
}
